package cn.swh.guguanjia.mapper;

import cn.swh.guguanjia.entity.SysResource;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@org.apache.ibatis.annotations.Mapper
public interface SysResourceMapper extends Mapper<SysResource> {

    @SelectProvider(type = SysResourceProvider.class, method = "selectPage")
    List<SysResource> selectPage(Map<String, Object> map);

    @Select("SELECT " +
            " sre.*  " +
            "FROM " +
            " sys_role_resource srr, " +
            " sys_resource sre  " +
            "WHERE " +
            " srr.role_id = #{rid}  " +
            " AND sre.del_flag = 0  " +
            " AND srr.resource_id = sre.id")
    List<SysResource> selectById(long rid);

    @Select("SELECT DISTINCT " +
            " sre.id, " +
            " sre.`name`, " +
            " sre.common, " +
            " sre.icon, " +
            " sre.sort, " +
            " sre.parent_id, " +
            " sre.type, " +
            " sre.url, " +
            " sre.description, " +
            " sre.`status`, " +
            " sre.parent_ids, " +
            " sre.create_date, " +
            " sre.update_date, " +
            " sre.create_by, " +
            " sre.update_by, " +
            " sre.del_flag, " +
            " sre.permission_str  " +
            "FROM " +
            " sys_user_role sur, " +
            " sys_role sro, " +
            " sys_role_resource srr, " +
            " sys_resource sre  " +
            "WHERE " +
            " sur.user_id = 45  " +
            " AND sre.del_flag = 0  " +
            " AND sre.type = 0  " +
            " AND sur.role_id = sro.id  " +
            " AND srr.resource_id = sre.id  " +
            "ORDER BY sort ASC " +
            " ")
    List<SysResource> selectByUid(long uid);

    @Select("SELECT *  FROM " +
            " sys_resource  " +
            "WHERE " +
            " type = 0  " +
            " AND del_flag = 0 " +
            " AND common = 0  " +
            " AND url <> ''")
    List<SysResource> selectResources();
}